package com.entrance;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.landmesure.bluetoothchat.databinding.ActivityLoginBinding;
import com.landmesure.communication.CommunicationPlatform;
import com.util.OkHttpUtil;

import org.json.JSONException;
import org.json.JSONObject;

public class LoginActivity extends AppCompatActivity {

    private ActivityLoginBinding activityLoginBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityLoginBinding = ActivityLoginBinding.inflate(getLayoutInflater());
        setContentView(activityLoginBinding.getRoot());
    }


    public void loginClick(View view) {
        EditText etName = activityLoginBinding.etName;
        EditText etPassword = activityLoginBinding.etPassword;
        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(intent);
        finish();
/*        if (etName.getText().toString().isEmpty() || etPassword.getText().toString().isEmpty()) {
            Toast.makeText(this, "用户名或密码为空", Toast.LENGTH_LONG).show();
            return;
        }
        {
            OkHttpUtil okHttpUtil = OkHttpUtil.getInstance();
            okHttpUtil.sendJson(CommunicationPlatform.loginUrl + "?userName=" + etName.getText() + "&password=" + etPassword.getText(),
                    "", new OkHttpUtil.Fun4() {
                        @Override
                        public void onResponse(JSONObject jsonObject) throws JSONException {
                            if (jsonObject.getBoolean("success")) {
                                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                                startActivity(intent);
                                finish();
                            } else {
                                Toast.makeText(getApplicationContext(), "密码或用户名错误", Toast.LENGTH_LONG).show();
                            }
                        }

                        @Override
                        public void onFailure() {
                            Toast.makeText(getApplicationContext(), "登陆失败", Toast.LENGTH_LONG).show();
                        }
                    });
        }*/
    }

}
